/**
 * 
 */
package com.rapwaves.feeds.widgets;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.rapwaves.feeds.FeedItem;
import com.rapwaves.feeds.FeedOwner;

/**
 * @author asanthan
 * 
 */
public class FeedItemUI extends Composite {

	private static FeedItemUIUiBinder uiBinder = GWT.create(FeedItemUIUiBinder.class);

	interface FeedItemUIUiBinder extends UiBinder<Widget, FeedItemUI> {
	}

	@UiField
	HorizontalPanel feedItemPanel;

	@UiField
	VerticalPanel htmlPanel;

	@UiField
	Image profileImage;

	@UiField
	Label name;

	FeedItem feedItem;

	@UiHandler("name")
	public void handleClick(ClickEvent e) {
		Window.open(feedItem.getFeedOwner().getProfileUrl(), "_blank", "");
	}

	public FeedItemUI(FeedItem feedItem) {
		initWidget(uiBinder.createAndBindUi(this));
		this.feedItem = feedItem;
		setFeedOwner();
		feedItemPanel.setCellHorizontalAlignment(htmlPanel, VerticalPanel.ALIGN_LEFT);
	}

	public void setFeedOwner() {
		FeedOwner feedOwner = feedItem.getFeedOwner();
		profileImage.setUrl(feedOwner.getPhotoUrl());
		name.setText(feedOwner.getName());
	}

	public void addFeedContents(Widget feedContents) {
		htmlPanel.add(feedContents);
	}

	public void addFeedActions(Widget feedActions) {
		htmlPanel.add(feedActions);
	}
}
